<?php

namespace app\api\controller;

/**
 * 行政区划管理
 *
 * @icon fa fa-circle-o
 */
class Region extends Base
{

    /**
     * Region模型对象
     * @var \app\admin\model\Region
     */
    protected $noNeedLogin = ['*'];
    public function get_list()
    {
        $region = new \app\common\model\Region();
        //查询出所有医院的市code
        $hospital = db('hospital')->column('city_id');
        if($hospital){
            $hospital = array_unique($hospital);
        }
        $where['level']=2;
        if($hospital){
            $where['code']=['in',$hospital];
        }
        $info =$region->field('code,level,name,first_name')->where($where)->order('sort desc')->select();

        $info=collection($info)->toArray();
        $hot = $region->field('code,level,name,first_name')->where(['level'=>2,'hot'=>1])->order('sort desc')->select();
        if($info){
            $info = groupByInitials($info,'first_name');
        }
        $this->success('获取成功',['info'=>$info,'hot'=>$hot],200);
    }
    public function get_list2()
    {
        $region = new \app\common\model\Region();
        //查询出所有医院的市code
        $hospital = db('hospital')->column('city_id');
        if($hospital){

        }
        $info =$region->field('code,level,name,first_name')->where('level',2)->order('sort desc')->select();

        $info=collection($info)->toArray();
        $hot = $region->field('code,level,name,first_name')->where(['level'=>2,'hot'=>1])->order('sort desc')->select();
        if($info){
            $info = groupByInitials($info,'first_name');
        }
        $this->success('获取成功',['info'=>$info,'hot'=>$hot],200);
    }
}
